#include <stdio.h>
#include "helper.h"
#include "bruch.h"
/*
 * bruch.c
 *
 *  Created on: 15.08.2011
 *      Author: stephan
 */

Ratio multi(Ratio bruch1, Ratio bruch2){
	Ratio result;
	result.nenner=bruch1.nenner * bruch2.nenner;
	result.zaehler=bruch1.zaehler * bruch2.zaehler;
	kuerze(&result);
	return result;
}

Ratio divi(Ratio bruch1, Ratio bruch2){
	Ratio result;
	result.zaehler=bruch1.zaehler * bruch2.nenner;
	result.nenner=bruch1.nenner * bruch2.zaehler;
	kuerze(&result);
	return result;
}

Ratio plus(Ratio bruch1, Ratio bruch2){
	Ratio result;
	Ratio t1;
	Ratio t2;
	t1=weiter(bruch1,bruch2.nenner);
	t2=weiter(bruch2,bruch1.nenner);
	result.nenner=t1.nenner;
	result.zaehler=t1.zaehler+t2.zaehler;
	kuerze(&result);
	return result;
}

Ratio minus(Ratio bruch1, Ratio bruch2){
	Ratio result;
	Ratio t1;
	Ratio t2;
	t1=weiter(bruch1,bruch2.nenner);
	t2=weiter(bruch2,bruch1.nenner);
	result.nenner=t1.nenner;
	result.zaehler=t1.zaehler-t2.zaehler;
	kuerze(&result);
	return result;
}


Ratio setBruch(){
	Ratio temp;
	char op;
	scanf("%d%c%d", &temp.zaehler, &op, &temp.nenner);
	return temp;
	}

void print_bruch(Ratio x){
	printf("%d/%d\n", x.zaehler,x.nenner);
}

Ratio ratio_fromString(char *x){
	Ratio temp;
	char op;
	sscanf(x, "%d%c%d", &temp.zaehler, &op, &temp.nenner);
	return temp;
	}




